unit Graf1u;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TfrmGraf1 = class(TForm)
    gpbGraf1: TGroupBox;
    lblHoejre: TLabel;
    lblVenstre: TLabel;
    btnNBase: TBitBtn;
    btnpH: TBitBtn;
    btnTemp: TBitBtn;
    btnOxygen: TBitBtn;
    btnFeedSpeed: TBitBtn;
    btnFeedDoses: TBitBtn;
    btnAlternative11: TBitBtn;
    btnAlternative21: TBitBtn;
    btnAcidDoses: TBitBtn;
    btnTempChanges: TBitBtn;
    btnRPM: TBitBtn;
    btnRPMchanges: TBitBtn;
    btnAlternative12: TBitBtn;
    btnAlternative22: TBitBtn;
    gpbAxisControl: TGroupBox;
    lblAuto: TLabel;
    lblManuel: TLabel;
    lblInterval: TLabel;
    gpbLeft: TGroupBox;
    radLA: TRadioButton;
    radLM: TRadioButton;
    gpbRight: TGroupBox;
    radRM: TRadioButton;
    radRA: TRadioButton;
    gpbXaxis: TGroupBox;
    radXM: TRadioButton;
    radXA: TRadioButton;
    lblLeft: TLabel;
    lblRigth: TLabel;
    lblXaxis: TLabel;
    edtLmin: TEdit;
    edtLmax: TEdit;
    edtRmin: TEdit;
    edtRmax: TEdit;
    edtXmin: TEdit;
    edtXmax: TEdit;
    lblShowLast: TLabel;
    edtShowLast: TEdit;
    radShowLast: TCheckBox;
    btnApply: TButton;
    Button1: TButton;
    btnLLight: TBitBtn;
    procedure btnpHClick(Sender: TObject);
    procedure btnTempClick(Sender: TObject);
    procedure btnOxygenClick(Sender: TObject);
    procedure btnFeedDosesClick(Sender: TObject);
    procedure btnFeedSpeedClick(Sender: TObject);
    procedure btnAlternative11Click(Sender: TObject);
    procedure btnAlternative12Click(Sender: TObject);
    procedure btnAlternative22Click(Sender: TObject);
    procedure btnNBaseClick(Sender: TObject);
    procedure btnAcidDosesClick(Sender: TObject);
    procedure btnTempChangesClick(Sender: TObject);
    procedure btnRPMClick(Sender: TObject);
    procedure btnRPMchangesClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure btnApplyClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnAlternative21Click(Sender: TObject);
    procedure btnLLightClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGraf1: TfrmGraf1;
  Filsti2, RightAxis, ABase, AAcid, ATempCh, ARpm, ARpmCh, A12, A22,
  LeftAxis, ApH, ATemp, AOxy, AFeedD, AFeedSp, AA11, AA21, ALight: string;
  Savegraph: boolean;

implementation

uses unit1;

{$R *.dfm}

Procedure OpdateAxis;
begin
if frmGraf1.btnTempChanges.Font.Color = clLime then
  begin
  ATempCh := ' [# Temp Changes] ';
  Form1.Chart1.Series[2].Active := true;
  end
else
  begin
  ATempCh := '';
  Form1.Chart1.Series[2].Active := false;
  end;
if frmGraf1.btnAcidDoses.Font.Color = clLime then
  begin
  AAcid := ' [# Acid Doses] ';
  Form1.Chart1.Series[9].Active := true;
  end
else
  begin
  AAcid := '';
  Form1.Chart1.Series[9].Active := false;
  end;
if frmGraf1.btnAlternative11.Font.Color = clLime then
  begin
  AA11 := ' [Alternative 11] ';
  Form1.Chart1.Series[11].Active := true;
  end
else
  begin
  AA11 := '';
  Form1.Chart1.Series[11].Active := false;
  end;
if frmGraf1.btnAlternative12.Font.Color = clLime then
  begin
  A12 := ' [# Alternative 12] ';
  Form1.Chart1.Series[12].Active := true;
  end
else
  begin
  A12 := '';
  Form1.Chart1.Series[12].Active := false;
  end;
if frmGraf1.btnAlternative21.Font.Color = clLime then
  begin
  AA21 := ' [Alternative 21] ';
  Form1.Chart1.Series[13].Active := true;
  end
else
  begin
  AA21 := '';
  Form1.Chart1.Series[13].Active := false;
  end;
if frmGraf1.btnAlternative22.Font.Color = clLime then
  begin
  A22 := ' [# Alternative 22] ';
  Form1.Chart1.Series[14].Active := true;
  end
else
  begin
  A22 := '';
  Form1.Chart1.Series[14].Active := false;
  end;
if frmGraf1.btnFeedDoses.Font.Color = clLime then
  begin
  AFeedD := ' [# Feed Doses] ';
  Form1.Chart1.Series[5].Active := true;
  end
else
  begin
  AFeedD := '';
  Form1.Chart1.Series[5].Active := false;
  end;
if frmGraf1.btnFeedSpeed.Font.Color = clLime then
  begin
  AFeedSp := ' [Feed Speed] ';
  Form1.Chart1.Series[10].Active := true;
  end
else
  begin
  AFeedSp := '';
  Form1.Chart1.Series[10].Active := false;
  end;
if frmGraf1.btnNBase.Font.Color = clLime then
  begin
  ABase := ' [# Base Doses] ';
  Form1.Chart1.Series[4].Active := true;
  end
else
  begin
  ABase := '';
  Form1.Chart1.Series[4].Active := false;
  end;
if frmGraf1.btnOxygen.Font.Color = clLime then
  begin
  AOxy := ' [Oxygen] ';
  Form1.Chart1.Series[6].Active := true;
  end
else
  begin
  AOxy := '';
  Form1.Chart1.Series[6].Active := false;
  end;
if frmGraf1.btnpH.Font.Color = clLime then
  begin
  ApH := ' [pH] ';
  Form1.Chart1.Series[1].Active := true;
  end
else
  begin
  ApH := '';
  Form1.Chart1.Series[1].Active := false;
  end;
if frmGraf1.btnRPMchanges.Font.Color = clLime then
  begin
  ARpmCh := ' [# RPM Changes] ';
  Form1.Chart1.Series[7].Active := true;
  end
else
  begin
  ARpmCh := '';
  Form1.Chart1.Series[7].Active := false;
  end;
if frmGraf1.btnRPM.Font.Color = clLime then
  begin
  ARpm := ' [RPM] ';
  Form1.Chart1.Series[8].Active := true;
  end
else
  begin
  ARpm := '';
  Form1.Chart1.Series[8].Active := false;
  end;
if frmGraf1.btnTemp.Font.Color = clLime then
  begin
  ATemp := ' [Temperature] ';
  Form1.Chart1.Series[3].Active := true;
  end
else
  begin
  ATemp := '';
  Form1.Chart1.Series[3].Active := false;
  end;
if frmGraf1.btnLLight.Font.Color = clLime then
  begin
  ALight := ' [Light] ';
  Form1.Chart1.Series[15].Active := true;
  end
else
  begin
  ALight := '';
  Form1.Chart1.Series[15].Active := false;
  end;
RightAxis := ABase + AAcid + ATempCh + ARpm + ARpmCh + A12 + A22;
LeftAxis := ApH + ATemp + AOxy + AFeedD + AFeedSp + AA11 + AA21 + ALight;
Form1.Chart1.RightAxis.Title.Caption := RightAxis;
Form1.Chart1.LeftAxis.Title.Caption := LeftAxis;
end;


Procedure GemGraf;
begin
  if Form1.SavePictureDialog1.Execute = true then
    begin
      if MessageDlg('Are you sure you want to overwrite this file? If a file with this name excist, it will be overwritten!',mtConfirmation,[mbYes, mbNo],0) = mrYes then
        begin
          Filsti2:= Form1.SavePicturedialog1.Filename; //filens placering gemmes i (den globale) variabel Filsti
          savegraph := true;
        end
      else
        begin
          MessageDlg('Snapshot not saved.',mtwarning,[mbOK],0);
          savegraph := false;
        end; //if overskriv end
    end
  else
    begin
      MessageDlg('Snapshot not saved.',mtwarning,[mbOK],0);
      savegraph := false;
    end;
  end; //if excecute end


procedure TfrmGraf1.btnApplyClick(Sender: TObject);
begin
//Change Left axis
if frmGraf1.radLA.Checked = true then
  begin
    Form1.Chart1.LeftAxis.Automatic := true;
  end
else
  begin
    Form1.Chart1.LeftAxis.Automatic := false;
    Form1.Chart1.LeftAxis.Minimum := StrToInt(frmGraf1.edtLmin.Text);
    Form1.Chart1.LeftAxis.Maximum := StrToInt(frmGraf1.edtLmax.Text);
  end;
//Change Right axis
if frmGraf1.radRA.Checked = true then
  begin
    Form1.Chart1.RightAxis.Automatic := true;
  end
else
  begin
    Form1.Chart1.RightAxis.Automatic := false;
    Form1.Chart1.RightAxis.Minimum := StrToInt(frmGraf1.edtRmin.Text);
    Form1.Chart1.RightAxis.Maximum := StrToInt(frmGraf1.edtRmax.Text);
  end;
//Change X axis
if frmGraf1.radShowLast.Checked = true then
  begin
    Form1.Chart1.BottomAxis.Automatic := false;
    ShowLastInterval := StrToInt(frmGraf1.edtShowLast.Text);
    ShowLast := true;
  end
else
if frmGraf1.radXA.Checked = true then
  begin
    Form1.Chart1.BottomAxis.Automatic := true;
  end
else
  begin
    Form1.Chart1.BottomAxis.Automatic := false;
    Form1.Chart1.BottomAxis.Minimum := StrToInt(frmGraf1.edtXmin.Text);
    Form1.Chart1.BottomAxis.Maximum := StrToInt(frmGraf1.edtXmax.Text);
  end;
end;

procedure TfrmGraf1.Button1Click(Sender: TObject);
begin
GemGraf;
if savegraph = true then
Form1.Chart1.SaveToBitmapFile(Filsti2);
end;

procedure TfrmGraf1.FormCreate(Sender: TObject);
begin
OpdateAxis;
end;

procedure TfrmGraf1.btnTempChangesClick(Sender: TObject);
begin
if  frmGraf1.btnTempChanges.Font.Color = clLime then
  begin
    frmGraf1.btnTempChanges.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnTempChanges.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnAcidDosesClick(Sender: TObject);
begin
if  frmGraf1.btnAcidDoses.Font.Color = clLime then
  begin
    frmGraf1.btnAcidDoses.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnAcidDoses.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnAlternative11Click(Sender: TObject);
begin
if  frmGraf1.btnAlternative11.Font.Color = clLime then
  begin
    frmGraf1.btnAlternative11.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnAlternative11.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnAlternative12Click(Sender: TObject);
begin
if  frmGraf1.btnAlternative12.Font.Color = clLime then
  begin
    frmGraf1.btnAlternative12.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnAlternative12.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnAlternative21Click(Sender: TObject);
begin
if  frmGraf1.btnAlternative21.Font.Color = clLime then
  begin
    frmGraf1.btnAlternative21.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnAlternative21.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnAlternative22Click(Sender: TObject);
begin
if  frmGraf1.btnAlternative22.Font.Color = clLime then
  begin
    frmGraf1.btnAlternative22.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnAlternative22.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnFeedDosesClick(Sender: TObject);
begin
if  frmGraf1.btnFeedDoses.Font.Color = clLime then
  begin
    frmGraf1.btnFeedDoses.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnFeedDoses.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnFeedSpeedClick(Sender: TObject);
begin
if  frmGraf1.btnFeedSpeed.Font.Color = clLime then
  begin
    frmGraf1.btnFeedSpeed.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnFeedSpeed.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnLLightClick(Sender: TObject);
begin
if  frmGraf1.btnLLight.Font.Color = clLime then
  begin
    frmGraf1.btnLLight.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnLLight.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnNBaseClick(Sender: TObject);
begin
if  frmGraf1.btnNBase.Font.Color = clLime then
  begin
    frmGraf1.btnNBase.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnNBase.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnOxygenClick(Sender: TObject);
begin
if  frmGraf1.btnOxygen.Font.Color = clLime then
  begin
    frmGraf1.btnOxygen.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnOxygen.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnpHClick(Sender: TObject);
begin
if  frmGraf1.btnpH.Font.Color = clLime then
  begin
    frmGraf1.btnpH.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnpH.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnRPMchangesClick(Sender: TObject);
begin
if  frmGraf1.btnRPMchanges.Font.Color = clLime then
  begin
    frmGraf1.btnRPMchanges.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnRPMchanges.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnRPMClick(Sender: TObject);
begin
if  frmGraf1.btnRPM.Font.Color = clLime then
  begin
    frmGraf1.btnRPM.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnRPM.Font.Color := clLime;
  end;
OpdateAxis;
end;

procedure TfrmGraf1.btnTempClick(Sender: TObject);
begin
if  frmGraf1.btnTemp.Font.Color = clLime then
  begin
    frmGraf1.btnTemp.Font.Color := clRed;
  end
else
  begin
    frmGraf1.btnTemp.Font.Color := clLime;
  end;
OpdateAxis;
end;

end.
